import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.desktop.Window
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import java.awt.image.BufferedImage
import java.io.File
import java.net.URL
import javax.imageio.ImageIO

@ExperimentalAnimationApi
fun main() = Window(
    title = "compose 桌面应用 - 登录",
    icon = ImageIO.read(File("D:\\Project\\ComposeDesktopTest\\src\\main\\resources\\images\\ic_launcher.png"))
) {
    val imagePath = imageResource("images/galaxy.jpg")
    var count by remember { mutableStateOf(0) }
    var elevation by remember { mutableStateOf(10.dp) }

//    MaterialTheme {
//        val typography = MaterialTheme.typography
//        ScrollableColumn(Modifier.padding(5.dp).clickable {
//            count = 30
//            elevation = 0.dp
//        }) {
//            val imageModifier = Modifier
//                .wrapContentHeight()
//                .wrapContentWidth()
//                .clip(shape = RoundedCornerShape(4.dp))
//            Card(elevation = elevation) { Image(imagePath, modifier = imageModifier)}
//            Spacer(modifier = Modifier.preferredHeight(16.dp))
//            Button(onClick = {count++}) {
//                Text(if (count == 0) "Hello World!" else "counter: $count", style = typography.h6)
//            }
//        }
//
//    }

//    MaterialTheme {
//        Card {
//            var expaned by remember { mutableStateOf(false) }
//            Column(modifier = Modifier.clickable { expaned = !expaned }) {
//                Image(imagePath, modifier = Modifier.height(450.dp))
//                AnimatedVisibility(expaned) {
//                    Text(text = "我是李大帅", style = MaterialTheme.typography.h2)
//                }
//            }
//        }
//    }

    MaterialTheme {
        Column(
            modifier = Modifier.padding(10.dp).fillMaxHeight().fillMaxWidth(),
            verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally
        ) {
            var name by remember { mutableStateOf("") }
            OutlinedTextField(
                value = name,
                onValueChange = { name = it },
                label = { Text("账号") }
            )
            var password by remember { mutableStateOf("") }
            OutlinedTextField(
                value = password,
                onValueChange = { password = it },
                label = { Text("密码") },
                visualTransformation = PasswordVisualTransformation(),
                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
            )
            Button(
                onClick = {},
                modifier = Modifier.width(250.dp).padding(20.dp)
            ) {
                Text(text = "登录")
            }
        }
    }
}
